package org.edu.modules.classChoise.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.edu.modules.classChoise.entity.*;
import org.edu.modules.classChoise.mapper.VeJwSxjxMapper;

import org.edu.modules.classChoise.mapper.VeJwSxjxsecMapper;
import org.edu.modules.classChoise.mapper.VeJwSxjxstuMapper;
import org.edu.modules.classChoise.mapper.VeJwXkdjMapper;
import org.edu.modules.classChoise.service.IVeJwSxjxService;
import org.edu.modules.classChoise.vo.VeJwXkxzVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import org.springframework.transaction.annotation.Transactional;
import org.edu.modules.classChoise.vo.VeJwSxjxVO;
/**
 * @Description: 选课时间
 * @Author:
 * @Date:   2021-05-14
 * @Version: V1.0
 */
@Service
public class VeJwSxjxServiceImpl extends ServiceImpl<VeJwSxjxMapper, VeJwSxjx> implements IVeJwSxjxService {
    @Autowired
    private VeJwSxjxsecMapper veJwSxjxsecMapper;
    @Autowired
    private VeJwSxjxstuMapper veJwSxjxstuMapper;
    @Autowired
    private VeJwSxjxMapper veJwSxjxMapper;

    @Override
    @Transactional
    public boolean setScheduleForClass(List<VeJwSxjxsec> veJwSxjxsecs,String sxjxid) {
        try {
            veJwSxjxsecMapper.deleteAll(Integer.parseInt(sxjxid));
            for (VeJwSxjxsec veJwSxjxsec : veJwSxjxsecs) {
                //veJwBpksj.setId(null);
                veJwSxjxsecMapper.insert(veJwSxjxsec);
            }
            return true;
        }
        catch (Exception ex){
            return false;
        }
    }

    @Override
    @Transactional
    public boolean save(VeJwSxjxVO veJwSxjxVO) {
        VeJwSxjx veJwSxjx = new VeJwSxjx();
        BeanUtils.copyProperties(veJwSxjxVO, veJwSxjx);
        try {
            int ret = veJwSxjxMapper.insert(veJwSxjx);
            if(ret<1){
                return false;
            }
            int sxjxId = veJwSxjx.getId();
            for(VeJwSxjxsec veJwSxjxsec : veJwSxjxVO.getSxjxsec()){
                veJwSxjxsec.setSxjxid(sxjxId);
                veJwSxjxsecMapper.insert(veJwSxjxsec);
            }
            return true;
        }
        catch (Exception ex){
            return false;
        }
    }
    @Override
    public List<Map<String, Object>> selectMapsPage1(){

        return veJwSxjxMapper.selectMapsPage1();
    }
    @Override
    public List<Map<String, Object>> selectJiaocaiPage(){

        return veJwSxjxMapper.selectJiaocaiPage();
    }
    @Override
    public List<Map<String, Object>> selectSxjxsecPage(String sxjxid){

        return veJwSxjxMapper.selectSxjxsecPage(sxjxid);
    }

    @Override
    public List<Map<String, Object>> selectCoursePage(){

        return veJwSxjxMapper.selectCoursePage();
    }

    @Override
    @Transactional
    public boolean updateById(VeJwSxjxVO veJwSxjxVO) {
        VeJwSxjx veJwSxjx = new VeJwSxjx();
        BeanUtils.copyProperties(veJwSxjxVO, veJwSxjx);
        try {
            int ret = veJwSxjxMapper.updateById(veJwSxjx);
            if(ret<1){
                return false;
            }
            int sxjxId = veJwSxjx.getId();
            veJwSxjxsecMapper.deleteAll(sxjxId);
            for(VeJwSxjxsec veJwSxjxsec : veJwSxjxVO.getSxjxsec()){
                veJwSxjxsec.setSxjxid(sxjxId);
                veJwSxjxsecMapper.insert(veJwSxjxsec);
            }
            return true;
        }
        catch (Exception ex){
            return false;
        }
    }

    @Override
    @Transactional
    public String selectjiaoshiName(int jiaoshiId) {
        try {
            String sections= veJwSxjxMapper.selectjiaoshiName(jiaoshiId);
            return sections;
        }
        catch (Exception ex){
            return "";
        }
    }
    @Override
    @Transactional
    public String selectspecName(int specId) {
        try {
            String specname= veJwSxjxMapper.selectspecName(specId);
            return specname;
        }
        catch (Exception ex){
            return "";
        }
    }
    @Override
    @Transactional
    public String selectgradeName(int gradeId) {
        try {
            String gradename= veJwSxjxMapper.selectgradeName(gradeId);
            return gradename;
        }
        catch (Exception ex){
            return "";
        }
    }
    @Override
    @Transactional
    public String selectteacherName(int teacherId) {
        try {
            String teachername= veJwSxjxMapper.selectteacherName(teacherId);
            return teachername;
        }
        catch (Exception ex){
            return "";
        }
    }

}
